﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RpgLibrary.WorldClasses;

namespace XLevelEditor
{
    public partial class FormNewLevel : Form
    {
        #region Field Region
    
        LevelData levelData;
        
        #endregion
    
        #region Property Region
        
        public LevelData LevelData
        {
            get { return levelData; }
        }

        #endregion

        #region Constructor Region
        
        public FormNewLevel()
        {
            InitializeComponent();
            btnOK.Click += new EventHandler(btnOK_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);

            SetDefaultValues();
        }
        #endregion

        private void SetDefaultValues()
        {
            tbLevelName.Text = "Starting Level";
            tbMapName.Text = "Village";
            nudMapWidth.Value = 100;
            nudMapHeight.Value = 100;
        }

        #region Button Event Handler Region
        
        void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbLevelName.Text))
            {
                MessageBox.Show("You must enter a name for the level.", "Missing Level Name");
                return;
            }

            if (string.IsNullOrEmpty(tbMapName.Text))
            {
                MessageBox.Show("You must enter a name for the map of the level.", "Missing Map Name");
                return;
            }

            levelData = new RpgLibrary.WorldClasses.LevelData(
                tbLevelName.Text,
                tbMapName.Text,
                (int)nudMapWidth.Value,
                (int)nudMapHeight.Value,
                new List<string>(),
                new List<string>(),
                new List<string>());

            this.DialogResult = DialogResult.OK;
        
            this.Close();
        }
        
        void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        
        #endregion
    }
}